local extension = Package("freak_alliance_vassal")
extension.extensionName = "freak_alliance"

Fk:loadTranslationTable{
  ["freak_alliance"] = "怀异集", 
  ["freak_alliance_vassal"] = "怀异集·天柱",
  ["fa"] = "怀异",
}

local fa__zangba = General(extension, "fa__zangba", "wei", 4,4)

local fa__hengjiang = fk.CreateTriggerSkill{
  name = "fa__hengjiang",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.GameStart, fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
      if event == fk.GameStart then
          return table.every(player.room.alive_players, function (p)return p:getMark("@@fa__zang") == 0 end)
      elseif event == fk.Damaged then
          return target == player and player:hasSkill(self)
        end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.GameStart then
      local room = player.room
      room:notifySkillInvoked(player, self.name)
      room:setPlayerMark(player, "@@fa__zang", 1)
      local targets = table.map(room:getOtherPlayers(player), Util.IdMapper)
      local tos = room:askForChoosePlayers(player, targets, 1, 1, "#fa__hengjiang-choose", self.name, false, true)
      if #tos > 0 then
        local to = room:getPlayerById(tos[1])
        room:handleAddLoseSkills(player, "-fa__hengjiang", nil)
        room:handleAddLoseSkills(to, "fa__hengjiang", nil)
        for _, p in ipairs(room.alive_players) do
          if p:getMark("@@fa__zang") ~= 0 then
            room:setPlayerMark(p, "@@fa__zang", 1)
            p:drawCards(2, self.name)
         end
        end
      end
  else if event == fk.Damaged then
      local room = player.room
      room:notifySkillInvoked(player, self.name)
      local targets = table.map(room:getOtherPlayers(player), Util.IdMapper)
      local tos = room:askForChoosePlayers(player, targets, 1, 1, "#fa__hengjiang-choose", self.name, false, true)
      if #tos > 0 then
        local to = room:getPlayerById(tos[1])
        room:handleAddLoseSkills(player, "-fa__hengjiang", nil)
        room:handleAddLoseSkills(to, "fa__hengjiang", nil)
        for _, p in ipairs(room.alive_players) do
          if p:getMark("@@fa__zang") ~= 0 then
            room:setPlayerMark(p, "@@fa__zang", 1)
            p:drawCards(2, self.name)
        end
      end
    end
    end
  end
  end,
} 


fa__zangba:addSkill(fa__hengjiang)

Fk:loadTranslationTable{
  ["fa__zangba"] = "臧霸", 
  ["#fa__zangba"] = "豹凌江左",
  ["cv:fa__zangba"] = "天外之音",
  ["illustrator:fa__zangba"] = "君桓文化",
  ["designer:fa__zangba"] = "异议",

  ["fa__hengjiang"] = "横江",
  [":fa__hengjiang"] = "锁定技，游戏开始时，你获得“臧”，然后或你受到伤害后，你转移本技能并令有“臧”的角色摸两张牌。",
  ["@@fa__zang"] = "臧",
  ["#fa__hengjiang-choose"] = "请将 横江 交给另一名角色",

  ["$fa__hengjiang1"] = "青，徐四战之地，当唯曹公是瞻！",
  ["$fa__hengjiang2"] = "若假霸步骑万人，必能横行江表！",
  ["$fa__hengjiang3"] = "公明于利钝，宁肯捐吾等邪？",
  ["~fa__zangba"] = "临朝而夺兵，终是见疑于国...",
}

return extension